Stories = function(stories){
	
	this.stories = stories;

	this.init = function(persons){
		this.persons = persons;
	}

	this.getStory = function(lastStory){
		var amount = 1000,
			getThis = null;
			st = 0,
			stories = this.stories,
			l = 0,
			sameAmount = 0,
			rnd = 0;

		for( st = stories.length; st; st-- ) {
			l = stories[st-1].next.length;
			if( l == amount ) {
				sameAmount += 1;
			}
			if( l < amount ) {
				getThis = stories[st-1];
				amount = l;
			}
		}
		if( sameAmount > 2 ) {
			do{
				rnd = parseInt(Math.round(Math.random()*(stories.length-1)));
			}while( stories[rnd].name == lastStory );
			getThis = stories[rnd];
		}


		return getThis;
	}

	this.told = function(person){

		var rnd = 0,
			persons = this.persons,
			stories = this.stories,
			tmpNext = [],
			next = '',
			nCnt = 0,
			fcnt = 0,
			story = person.story;

		story.counter += 1;

		do{
			rnd = parseInt(Math.round(Math.random()*(persons.length-1)));
			fcnt += 1;
		}while( fcnt < 32 && persons[rnd].story != null && persons[rnd].name == person.name );

		if( fcnt >= 32 ) {
			return false;
		}

		for( nCnt = story.length; nCnt; nCnt-- ) {
			if( story.next[nCnt] != person.fullname ){
				tmpNext.push(person.fullname);
			}
		}

		tmpNext.push(persons[rnd].fullname);

		story.next = tmpNext;

		persons[rnd].story = person.story;
		
		person.story = null;

		return persons[rnd].fullname;

	}



}